package com.atguigu.a_string;
/*
    两个常量字符串进行拼接,那么可以共享结果地址 [常量相加结果固定] -> 常量优化机制
    字符串拼接时只要有变量参与,就会重新开辟一个新的空间存储结果 [不管结果内容的]


    结论 : 字符串做拼接非常消耗内存资源 [推荐使用StringBuffer/StringBuilder]


    str1 + str2 + str3

    "a" + "b" + "c"
 */
public class Test2 {
    public static void main(String[] args) {
        String str1 = "Hello";
        String str2 = "World";

        String str3 = "HelloWorld";//0001
        String str4 = "Hello" + "World";//0001
        String str5 = str1 + "World";//0002
        String str6 = "Hello" + str2;//0003
        String str7 = str1 + str2;//0004

        System.out.println(str3 == str4);//true
        System.out.println(str3 == str5);
        System.out.println(str3 == str6);
        System.out.println(str3 == str7);

        System.out.println(str4 == str5);
        System.out.println(str4 == str6);
        System.out.println(str4 == str7);

        System.out.println(str5 == str6);
        System.out.println(str5 == str7);

        System.out.println(str6 == str7);
    }
}
